﻿var h=$("#PingLun").outerHeight()
$(document).ready(function(){
	$("#VideoBanner").swiperBanner({"bannername":"bannerSwiper","nav":1,"prevnext":0})
	
	$("#PingLun").reset_topbom(".maincontent","margin-bottom")
	
	//直播互动 节目介绍
	$('#InteractionTab').Tab("li",".change",".Tab_nr","click")
	
	
	$("#PingLun .form .text").bind("focusin",function(){
		var self=$(this)
		$("#PingLun").css("margin-bottom",0)
		setTimeout(function(){
			$("html,body").animate({scrollTop:($(window).outerHeight()-h)/2+h},10)
		},300)
	})
	
	//礼物
	$.fn.gift()
})




$.fn.gift=function(){
	var giftlist=$("#giftList")
	var giftwindow=$("#giftsend")
	var giftwindow_zz=$("#giftsend_zz")
	$(".btn_gift").on("click",function(){
		
		  

			giftlist.toggle()
			$(this).toggleClass("btnchange");
			
			if(giftlist.is(":hidden"))
			{
				$("#PingLun").reset_topbom(".maincontent","margin-bottom")
			}
	})
	
	giftlist.find("li").on("click",function(){
		
		 
		 
		var self=$(this)
		var giftpic=self.find(".icongift_").attr("class")
		var giftname=self.attr("data-name")
		var giftprice=self.attr("data-price")
		giftwindow.find(".photo span").attr("class",giftpic)
		giftwindow.find("h4 strong").text(giftname)
		giftwindow.find("h4 em").text("（"+giftprice+"L币）").attr("data-price",giftprice)
		giftwindow.find(".sl_select li").removeClass("change")
		giftwindow.find(".sl_select li:first").addClass("change");
		$(this).addClass("change").siblings().removeClass("change");	
		 giftwindow.fadeIn()
		 giftwindow_zz.fadeIn()
	})
	giftwindow_zz.on("click",function(){
		giftlist.find("li").removeClass("change");	
		 giftwindow.fadeOut()
		 giftwindow_zz.fadeOut()
	})
	
	
	giftwindow.find(".sl_select li").on("click",function(){
		$(this).addClass("change").siblings().removeClass("change");	
			
		
		
	})
	
	giftwindow.find(".btn_send").on("click",function(){
		alert("点击发送")
		giftlist.find("li").removeClass("change");	
		 giftwindow.fadeOut()
		 giftwindow_zz.fadeOut()
		
	})
	
	
}

//重定位
$.fn.reset_topbom=function(obj,css){
	var self=$(this)
	var window_h=$(window).height()
	var window_w=$(window).width()
	if (self.length==0) return false;
	if ($(obj).length==0) return false;
	var h=self.outerHeight()
	if (window_w>750) window_w=750
	h=h/window_w*100
	$(obj).css(css,h+"%");
}


//选项卡切换
		$.fn.Tab=function(subtab,selectname,tab,action){
			var self=$(this);
			var select_=0;
			var addselectname=selectname.replace(".","")
			if (self.find(subtab).length==0) return false;
			if (self.find(subtab+selectname).length==0) 
			{self.find(subtab+":eq(0)").addClass(addselectname);}
			
			self.find(subtab).each(function(index, element) {
                if (!$(this).is(selectname))
				{
					self.parent().find(tab+":eq("+index+")").hide();
				}
            });
			self.find(subtab).bind(action,function(){
				self.find(subtab+selectname).removeClass(addselectname);
				$(this).addClass(addselectname);
				var index=$(this).index();
				self.siblings(tab).hide()
				self.siblings(tab+":eq("+index+")").show();
			})
		}
		
		
		
//广告
$.fn.swiperBanner=function(config){
	var self=$(this)
	if (self.length==0) return false;
	
	var ulobj=self .find("ul")
	var liobj=self .find("li")
	var nav,prevnext
	config.nav==1? nav='<div class="swiper-pagination"></div>':nav=''
	config.prevnext==1? prevnext='<div class="swiper-button-next"></div><div class="swiper-button-prev"></div>': prevnext=' '
	
	if (liobj.length>0)
	{
		liobj.each(function(index, element) {
            var htmls=$(this).html()
			$(this).replaceWith('<div class="swiper-slide">'+htmls+'</div>');
        });	
		ulobj.replaceWith('<div class="swiper-container" id="'+config.bannername+'"><div class="swiper-wrapper">'+ulobj.html()+'</div>'+nav+prevnext+'</div>')
		var swiper = new Swiper('#'+config.bannername, {
			pagination: '#'+config.bannername+' .swiper-pagination',
			nextButton: '#'+config.bannername+' .swiper-button-next',
			prevButton: '#'+config.bannername+' .swiper-button-prev',
			slidesPerView: 1,
			paginationClickable: true,
			spaceBetween: 1,
			loop: true
		});
	}
	
}



document.onreadystatechange = loading;//当页面加载状态改变的时候执行这个方法. 
function loading() 
{ 
	if(document.readyState =="complete")
	{$('#loading').fadeOut(300)}
} 	




